package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppMingxiDuihuan;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 账单明细-充值
 */
@Repository
public class AppMingxiDuihuanDao extends BaseDao<AppMingxiDuihuan> {

    /**
     * 查询列表
     */
    public List<AppMingxiDuihuan> findList(Integer userid, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_mingxi_duihuan where 1=1  ");
        sbStr.append(" and userid = ? ");
        paramList.add(userid);
        sbStr.append(" order by createtime desc");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppMingxiDuihuan.class,splitPage);
    }


    /**
     * 详情
     */
    public AppMingxiDuihuan get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_mingxi_duihuan where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppMingxiDuihuan.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppMingxiDuihuan haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 查询兑换钻石明显
     * @param pageBean
     * @return
     */
    public List<AppMingxiDuihuan> exchangeDetails(Integer userid,SplitPageBean pageBean) {
        StringBuilder str = new StringBuilder();
        List list = new ArrayList();
        str.append("select * from app_mingxi_duihuan where userid = ? ");
        list.add(userid);
        str.append(" order by createTime desc");
        String sql = str.toString();
        return this.queryList(sql,list,AppMingxiDuihuan.class,pageBean);
    }

    /**
     * 查询金豆兑换钻石 以订单号的明细
     * @param id
     * @return
     */
    public AppMingxiDuihuan selectDetailsById(String id) {
        StringBuilder str = new StringBuilder();
        List list = new ArrayList();
        str.append("select * from app_mingxi_duihuan where ordernumder = ?");
        list.add(id);
        String sql = str.toString();
        return this.queryObj(sql,list,AppMingxiDuihuan.class);
    }
}
